package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.util.ResponseCode.OK;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.entity.BrandPropertiesGroup;
import com.cheejee.goodscenter.module.response.BaseReponse;
import com.cheejee.goodscenter.module.response.PageReponse;
import com.cheejee.goodscenter.module.vo.BrandPropertiesGroupVo;
import com.cheejee.goodscenter.service.BrandPropertiesGroupService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author CARRY
 * @Date 2020年10月30日上午1:40:54
 */
@RestController
@RequestMapping("/brand/group")
@Api(tags = "品牌属性分组")
public class BrandPropertiesGroupController {
	@Resource
	private BrandPropertiesGroupService service;
	
	@GetMapping("/{brandId}")
	@ApiOperation("查询某品牌的所有品牌分组")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "brandId", value = "品牌ID", dataType = "int"),
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getByBrand(@PathVariable Integer brandId, int pageNum, int pageSize) {
		
		return new PageReponse(OK, "查询完成", service.queryBrandPropertiesGroup(brandId, null, pageNum, pageSize));
	}
	
	@PutMapping("/")
	@ApiOperation("新增品牌属性分组")
	public Object addGroup(@RequestBody BrandPropertiesGroupVo group) {
		BrandPropertiesGroup g = BrandPropertiesGroupVo.convert(null, group);
		service.addBrandPropertiesGroup(g);
		
		return BaseReponse.ok("新增完成", service.queryBrandPropertiesGroupById(g.getId()));
	}
	
	@PutMapping("/{id}")
	@ApiOperation("修改品牌属性分组")
	public Object changeGroup(@PathVariable Integer id, @RequestBody BrandPropertiesGroupVo group) {
		BrandPropertiesGroup g = BrandPropertiesGroupVo.convert(id, group);
		service.changeBrandPropertiesGroup(g);
		
		return BaseReponse.ok("修改完成", service.queryBrandPropertiesGroupById(g.getId()));
	}
	
	@DeleteMapping("/{id}")
	@ApiOperation(value = "删除品牌属性分组", notes = "支持多个删除")
	public Object deleteGroup(@PathVariable Integer[] id) {
		service.deleteBrandPropertiesGroup(id);
		
		return BaseReponse.ok("删除完成");
	}
	
}
